<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
    /**
     * Run the migrations.
     */
    public function up(): void
    {
        Schema::create('members', function (Blueprint $table) {
            $table->id();
            $table->string('name');
            $table->string('real_name');
            $table->string('email')->unique();
            $table->string('phone')->nullable();
            $table->text('address')->nullable();
            $table->date('registration_date');
            $table->integer('benefit_id')->default(0);
            $table->boolean('is_active')->default(true);
            $table->string('password'); // 密码字段
            $table->foreignId('current_team_id')->nullable();
            $table->string('profile_photo_path', 2048)->nullable();
            $table->rememberToken(); // 记住我 token
            $table->timestamps();
        });
        Schema::create('invitees', function (Blueprint $table) {
            $table->id();
            $table->string('name');
            $table->unsignedBigInteger('inviter_id')->nullable();
            $table->timestamps();
            // 使用 Nested Set 扩展包提供的字段
            $table->nestedSet();
        });
        Schema::create('benefits', function (Blueprint $table) {
            $table->id();
            $table->string('name');
            $table->text('description')->nullable();
            $table->timestamps();
        });
        Schema::create('member_benefits', function (Blueprint $table) {
            $table->id();
            $table->unsignedBigInteger('member_id');
            $table->unsignedBigInteger('benefit_id');
            $table->timestamps();
        });


    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::dropIfExists('members');
        Schema::dropIfExists('invitees');
        Schema::dropIfExists('benefits');
        Schema::dropIfExists('member_benefits');
    }
};
